<template>
  <li class="item-panel-item" draggable @dragstart="handleDragItem">
    <!-- 流程节点 -->
    <div class="item-panel-item-body process" v-if="nodeType === 'process'">
      <div class="item-panel-item-title">
        <span>{{ name }}</span>
      </div>
    </div>
    <!-- 判定节点 -->
    <div
      class="item-panel-item-body decision"
      v-else-if="nodeType === 'decision'"
    >
      <div class="diamond"></div>
      <div class="item-panel-item-title">
        <span>{{ name }}</span>
      </div>
    </div>
    <!-- 开始/结束 节点 -->
    <div
      class="item-panel-item-body termination"
      v-else-if="nodeType === 'termination'"
    >
      <div class="item-panel-item-title">
        <span>{{ name }}</span>
      </div>
    </div>
    <!-- 数据节点 -->
    <div class="item-panel-item-body data" v-else-if="nodeType === 'data'">
      <div class="item-panel-item-title">
        <span>{{ name }}</span>
      </div>
    </div>
    <!-- 子流程节点 -->
    <div
      class="item-panel-item-body subprocess"
      v-else-if="nodeType === 'subprocess'"
    >
      <div class="item-panel-item-title">
        <span>{{ name }}</span>
      </div>
    </div>
    <!-- 其他 -->
    <!-- <div class="vue-node-wrapper">
      <div class="vue-node-body">
        <i class="icon iconfont icon-edit"></i>
        <div class="title">
          {{ name }}
        </div>
      </div>
    </div> -->
  </li>
</template>

<script>
import EventBus from "../../event-bus/index";
import BusEvents from "../../event-bus/event-types";

export default {
  name: "item-panel-item",
  props: {
    item: {
      type: Object,
      default: () => {
        return {
          name: "矩形",
        };
      },
    },
  },
  computed: {
    name() {
      return this.item.name;
    },
    nodeClass() {
      return this.item.type.split(".")[0];
    },
    nodeType() {
      return this.item.type.split(".")[1];
    },
  },
  methods: {
    handleDragItem(e) {
      EventBus.$emit(BusEvents.INTERACT_ITEM_DRAG, { nodeData: this.item, e });
    },
  },
};
</script>

<style lang="less">
.item-panel-item {
  // width: 160px;
  // height: 40px;
  margin: 20px 0 20px 40px;
  cursor: move;
  user-select: none;

  .item-panel-item-body {
    // width: 100%;
    // height: 100%;

    display: flex;
    justify-content: center;
    align-items: center;

    &:hover {
      box-shadow: 1px 1px 1px 1px #666;
    }

    &.process {
      width: 160px;
      height: 80px;
      background-color: #63abf7;
    }

    &.decision {
      width: 200px;
      height: 80px;
      position: relative;

      // 菱形背景
      .diamond {
        /* 向左的三角形 */
        width: 0;
        height: 0;
        box-sizing: border-box;
        border: 98px solid #63abf7;
        border-top-width: 38px;
        border-bottom-width: 38px;
        border-left-color: transparent;
        border-top-color: transparent;
        border-bottom-color: transparent;
        position: absolute;
        left: -98px;

        display: flex;
        justify-content: center;
        align-items: center;

        &::after {
          content: "";
          position: absolute;
          box-sizing: border-box;
          border: 98px solid #63abf7;
          border-top-width: 38px;
          border-bottom-width: 38px;
          border-right-color: transparent;
          border-top-color: transparent;
          border-bottom-color: transparent;
          left: 98px;
        }
      }
    }

    &.termination {
      width: 160px;
      height: 70px;
      border-radius: 40px;
      background-color: #63abf7;
    }

    &.data {
      width: 128px;
      height: 80px;
      background-color: #63abf7;
      transform: skewX(-20deg);

      & > * {
        transform: skewX(20deg);
      }
    }

    &.subprocess {
      width: 160px;
      height: 80px;
      position: relative;
      background-color: #63abf7;

      &::before {
        content: "";
        position: absolute;
        width: 6px;
        height: 100%;
        left: 20px;
        background-color: #fff;
      }

      &::after {
        content: "";
        position: absolute;
        width: 6px;
        height: 100%;
        right: 20px;
        background-color: #fff;
      }
    }

    .item-panel-item-title {
      height: 24px;
      width: 60%;
      color: white;
      text-align: center;
      z-index: 9;
    }
  }
}
</style>
